package com.sc.nft.controller;

import cn.hutool.core.util.StrUtil;
import com.sc.nft.annotation.UserLogin;
import com.sc.nft.controller.request.*;
import com.sc.nft.entity.UserInfo;
import com.sc.nft.entity.vo.ecology.*;
import com.sc.nft.enums.RedisKeyEnum;
import com.sc.nft.exception.GlobalException;
import com.sc.nft.pool.UserPool;
import com.sc.nft.service.EcologyCastExchangeConfService;
import com.sc.nft.service.EcologyCastService;
import com.sc.nft.service.UserEcologyPointsWalletService;
import com.sc.nft.sup.ErrorCode;
import com.sc.nft.sup.PageRequest;
import com.sc.nft.sup.PageResult;
import com.sc.nft.sup.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.redisson.Redisson;
import org.redisson.api.RLock;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;
import java.util.concurrent.TimeUnit;

@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/ecology/pointWallet")
@Api(tags = "用户积分")
public class EcologyPointWalletController {

    private final UserEcologyPointsWalletService userEcologyPointsWalletService;

    @ApiOperation(value = "我的积分列表", notes = "我的积分列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/userPage", produces = MediaType.APPLICATION_JSON_VALUE)
    @UserLogin
    public PageResult<EcologyPointWalletPageVO> userPage(@Valid @RequestBody SaasIdPageReq request){
        return PageResult.success(userEcologyPointsWalletService.userPage(request.getPageNo(),request.getPageSize(),request.getUserCreatorId(), UserPool.getUserId()));
    }

    @ApiOperation(value = "积分支出记录", notes = "积分支出记录", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/userEcologyPointsExpend", produces = MediaType.APPLICATION_JSON_VALUE)
    @UserLogin
    public PageResult<EcologyPointWalletExpendPageVO> userEcologyPointsExpend(@Valid @RequestBody IdPageRequest request){
        return PageResult.success(userEcologyPointsWalletService.userEcologyPointsExpend(request.getPageNo(),request.getPageSize(),request.getId(), UserPool.getUserId()));
    }


}
